<template> 
    <el-card class="form-container" shadow="never">
        <el-form :model="pmsProductAttribute" :rules="rules" ref="PmsProductAttributeFrom" label-width="150px">


                    <el-form-item
                            label="shop:特性编号"
                            prop="id">
                        <el-input v-model="pmsProductAttribute.id" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="shop:特性名称(赠品，正品，残次品，打折, 满赠)"
                            prop="name">
                        <el-input v-model="pmsProductAttribute.name" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="productAttributeCategoryId"
                            prop="productAttributeCategoryId">
                        <el-input v-model="pmsProductAttribute.productAttributeCategoryId" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="属性选择类型：0->唯一；1->单选；2->多选"
                            prop="selectType">
                        <el-input v-model="pmsProductAttribute.selectType" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="属性录入方式：0->手工录入；1->从列表中选取"
                            prop="inputType">
                        <el-input v-model="pmsProductAttribute.inputType" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="可选值列表，以逗号隔开"
                            prop="inputList">
                        <el-input v-model="pmsProductAttribute.inputList" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="排序字段：最高的可以单独上传图片"
                            prop="sort">
                        <el-input v-model="pmsProductAttribute.sort" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="分类筛选样式：1->普通；1->颜色"
                            prop="filterType">
                        <el-input v-model="pmsProductAttribute.filterType" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="检索类型；0->不需要进行检索；1->关键字检索；2->范围检索"
                            prop="searchType">
                        <el-input v-model="pmsProductAttribute.searchType" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="相同属性产品是否关联；0->不关联；1->关联"
                            prop="relatedStatus">
                        <el-input v-model="pmsProductAttribute.relatedStatus" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="是否支持手动新增；0->不支持；1->支持"
                            prop="handAddStatus">
                        <el-input v-model="pmsProductAttribute.handAddStatus" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="属性的类型；0->规格；1->参数"
                            prop="type">
                        <el-input v-model="pmsProductAttribute.type" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="所属店铺"
                            prop="storeId">
                        <el-input v-model="pmsProductAttribute.storeId" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="shop:创建人"
                            prop="shopCreateby">
                        <el-input v-model="pmsProductAttribute.shopCreateby" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="shop:创建时间"
                            prop="shopCreatetime">
                        <el-input v-model="pmsProductAttribute.shopCreatetime" style="width: 370px;"/>
                    </el-form-item>


                    <el-form-item
                            label="shop:状态-是否删除 0-没有删除， 1-删除"
                            prop="shopStatus">
                        <el-input v-model="pmsProductAttribute.shopStatus" style="width: 370px;"/>
                    </el-form-item>


            <el-form-item>
                <el-button type="primary" @click="onSubmit('PmsProductAttributeFrom')">提交</el-button>
                <el-button v-if="!isEdit" @click="resetForm('PmsProductAttributeFrom')">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
    import {createPmsProductAttribute, getPmsProductAttribute, updatePmsProductAttribute} from '@/api/pms/pmsProductAttribute'
    import SingleUpload from '@/components/Upload/singleUpload'

    const defaultPmsProductAttribute = {
        name: ''
    };
    export default {
        name: 'PmsProductAttributeDetail',
        components: {SingleUpload},
        props: {
            isEdit: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
            pmsProductAttribute:
            Object.assign({},
        defaultPmsProductAttribute),
            rules: {
                name: [
                    {required: true, message: '请输入品牌名称', trigger: 'blur'},
                    {min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'}
                ],
                    logo
            :
                [
                    {required: true, message: '请输入品牌logo', trigger: 'blur'}
                ],
                    sort
            :
                [
                    {type: 'number', message: '排序必须为数字'}
                ],
            }
        }
        },
        created() {
            if (this.isEdit) {
                getPmsProductAttribute(this.$route.query.id).then(response => {
                    this.pmsProductAttribute = response.data;
            })
                ;
            } else {
                this.pmsProductAttribute = Object.assign({},
            defaultPmsProductAttribute)
                ;
            }
        },
        methods: {
            onSubmit(formName) {
                this.$refs[formName].validate((valid) => {
                    if(valid) {
                        this.$confirm('是否提交数据', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            if(this.isEdit
                    )
                        {
                            updatePmsProductAttribute(this.$route.query.id, this.pmsProductAttribute).then(response => {
                                if(response.code == 200
                        )
                            {
                                this.$refs[formName].resetFields();
                                this.$message({
                                    message: '修改成功',
                                    type: 'success',
                                    duration: 1000
                                });
                                this.$router.back();
                            }
                        else
                            {
                                this.$message({
                                    message: response.msg,
                                    type: 'error',
                                    duration: 1000
                                });
                            }

                        })
                            ;
                        }
                    else
                        {
                            createPmsProductAttribute(this.pmsProductAttribute).then(response => {
                                if(response.code == 200
                        )
                            {
                                this.$refs[formName].resetFields();
                                this.pmsProductAttribute = Object.assign({},
                            defaultPmsProductAttribute)
                                ;
                                this.$message({
                                    message: '提交成功',
                                    type: 'success',
                                    duration: 1000
                                });
                                this.$router.back();
                            }
                        else
                            {
                                this.$message({
                                    message: response.msg,
                                    type: 'error',
                                    duration: 1000
                                });
                            }

                        })
                            ;
                        }
                    })
                        ;

                    } else {
                        this.$message({
                            message: '验证失败',
                            type: 'error',
                            duration: 1000
                        });
                return false;
            }
            })
                ;
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.pmsProductAttribute = Object.assign({},
            defaultPmsProductAttribute)
                ;
            }
        }
    }
</script>
<style>
</style>


